package com.ds.lens.data.common.constant;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 检测类型
 */
public enum DetectionTypeEnum {
    /**
     * 静态基线
     */
    STATIC_STATE(1, "静态基线"),
    /**
     * 动态基线
     */
    DYNAMIC_STATE(2, "动态基线");

    @Getter
    private int code;
    @Getter
    private String desc;
    private static Map<Integer, DetectionTypeEnum> innerCacheMap = new HashMap<>(values().length);

    static {
        for (DetectionTypeEnum detectionTypeEnum : DetectionTypeEnum.values()) {
            innerCacheMap.put(detectionTypeEnum.getCode(), detectionTypeEnum);
        }
    }

    DetectionTypeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 通过来源数值转换为枚举类型
     */
    public static DetectionTypeEnum enumOf(int code) {
        return innerCacheMap.get(code) == null ? STATIC_STATE : innerCacheMap.get(code);
    }
}
